package com.lax.eurekaserver.config;

import com.netflix.appinfo.InstanceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.*;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class EurekaStateChangeListener {
    private Logger logger = LoggerFactory.getLogger(EurekaStateChangeListener.class);

    @EventListener
    public void listen(EurekaInstanceCanceledEvent event) {
        logger.warn(">>>>>>>>>>>>>>服务：{} -- {}正在下线",event.getServerId(),event.getAppName());
    }

    @EventListener
    public void listen(EurekaInstanceRegisteredEvent event) {
        InstanceInfo instanceInfo = event.getInstanceInfo();
        logger.warn(">>>>>>>>>>>>>>服务：{} -- 进行注册",instanceInfo.getAppName());
    }

    @EventListener
    public void listen(EurekaInstanceRenewedEvent event) {
        logger.warn(">>>>>>>>>>>>>>服务：{} -- {} -- 进行服务续约",event.getServerId(),event.getAppName());
    }

    @EventListener
    public void listen(EurekaRegistryAvailableEvent event) {
        logger.warn(">>>>>>>>>>>>>>注册中心启动");
    }

    @EventListener
    public void listen(EurekaServerStartedEvent event) {
        logger.warn(">>>>>>>>>>>>>>Eureka Server 启动");
    }

}
